import React, {Component} from 'react'
import { Link } from 'react-router'
import Writebar from './writebar'
import './sm-extend.min.css'
import Getemailbar from './getemailbar'
import './sm.min.css'
import './index.css'
import $ from 'jquery'

class Inbox extends Component{
    constructor(){
        super();
        this.state={
            list:'',
            emailinfo:''
        }
    }
    read(){

    }
    render(){
        var data=this.state.emailinfo
        var rows=[];
        for(var i=0;i<data.length;i++){
            rows.push(<div className="user col-100" onClick={this.read.bind(this)}>
                <div className="inboxemail col-100">{data[i].title}</div>
                <div className="inboxemail col-100">用户名:{data[i].sendtorname}</div>
            </div>)
        }
        return(
            <div>
                <div className="heidi"></div>
                <div className="emailtext">
                    <span className="cancel">X</span>
                    <div className="text"></div>
                </div>


            <div className=" inboxlist content">
                <div className="row no-gutter">
                    {rows}
                </div>
            </div>


            <Getemailbar/>
            </div>
    )

    }
    componentDidMount=()=>{
        var username = localStorage.getItem('name')
        var data={
            username:username,
        }
        $.post('http://127.0.0.1:8080/inboxtheme',data,function (data,textStatus,xhr) {
        this.setState({
           list:data,
            emailinfo:data[0].getemail
        });
            $('.user').click(function(){
                var sy = $(this).index()
                var username = localStorage.getItem('name');
                var data={
                    index:sy,
                    username:username,
                }
                $.post('http://127.0.0.1:8080/emailtext',data,function (data,textStatus,xhr) {
                    $('.emailtext').css('display','block');
                    $('.heidi').css('display','block');
                    $('.emailtext>.text').text(data)
                })
                $('.emailtext>.cancel').click(function(){
                    $('.emailtext').css('display','none');
                    $('.heidi').css('display','none');
                })

            })
    }.bind(this))


    }

}


export default Inbox